﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace WhittleList.RouteContraints
{
    public class MatchConstraint : IRouteConstraint
    {
        public MatchConstraint(params string[] matches)
        {
            Matches = matches;
        }

        public MatchConstraint(string match) : this(new string[]{match}){}

        public string[] Matches{get;set;}

        public virtual bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            foreach (var match in Matches)
            {
                if (match.Equals((values[parameterName] ?? "").ToString(), StringComparison.CurrentCultureIgnoreCase))
                    return true;
            }
            return false;
        }
    }
}
